/**   
 * @Title: UserSerivceImpl.java
 * @Package com.cityoneyes.service
 * @Description: TODO
 * @author Rick
 * @date 2011-8-3 下午11:56:55
 * @version V1.0   
 */
package com.cityoneyes.service.impl;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.cityoneyes.bean.User;
import com.cityoneyes.common.Constants;
import com.cityoneyes.dao.IUserDAO;
import com.cityoneyes.service.IUserService;

/**
 * @ClassName: UserSerivceImpl
 * @Description: TODO
 * @author Rick
 * @date 2011-8-3 下午11:56:55
 */
@Service
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = { Exception.class })
public class UserSerivceImpl extends BaseServiceImpl implements IUserService {

	@Autowired
	private IUserDAO userDao;
	
	@Override
	public User createUserByImei(String imei) {
		User user = new User();
		user.setCreateTime(new Date());
		user.setImei(imei);
		user.setLastLoginTime(user.getCreateTime());
		user.setOnline(Constants.USER_ON_LINE);
		super.add(user);
		return user;
	}

	@Override
	public User getUserByImei(String imei) {
		User user = userDao.getUserByImei(imei);
		if (user == null) {
			// 新建用户
			return createUserByImei(imei);
		}
		user.setOnline(Constants.USER_ON_LINE);
		user.setLastLoginTime(new Date());
		super.update(user);
		return user;
	}

}
